//
//  ViewController.m
//  Thread
//
//  Created by hyl on 16/7/12.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //一个NSThread对象就代表一条线程
    //创建（局部变量，当执行完run后自动销毁）
//    NSThread *thread=[[NSThread alloc]initWithTarget:self selector:@selector(run) object:nil];
    NSThread *thread=[[NSThread alloc]initWithTarget:self selector:@selector(run) object:@"HYL"];
    thread.name=@"hyl";
    //启动线程
    [thread start];
}
-(void) run{
    NSLog(@"fdsff");
    NSLog(@"%@",[NSThread mainThread]);
    NSLog(@"%i",[NSThread isMainThread]);
    NSThread *current=[NSThread currentThread];
    NSLog(@"%@",current);
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //创建线程后自动启动线程
//    [NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
    
    //隐式创建并创建线程
    [self performSelectorInBackground:@selector(run) withObject:nil];
}
@end
